package com.lihan.GetSeatInLib.Configs;

import org.quartz.JobDataMap;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.quartz.CronTriggerFactoryBean;
import org.springframework.scheduling.quartz.JobDetailFactoryBean;
import org.springframework.scheduling.quartz.SchedulerFactoryBean;

import com.lihan.GetSeatInLib.Jobs.Clean_LockTableSeat_ToLocked;
import com.lihan.GetSeatInLib.Jobs.TestJob;
import com.lihan.GetSeatInLib.Service.LibTableService;
import com.lihan.GetSeatInLib.Service.SeatService;

/**
 * 
 * @ClassName: QuartZConfig
 * @Description: 这里配置定时任务
 * @author ASUS
 * @date 2022年3月13日
 *
 */
@Configuration
@EnableScheduling
public class QuartZConfig {

	/*
	 * JobDetail---->Trigger---->ScheduleFactory
	 * 
	 * */
	
	@Autowired
	private LibTableService tableService;
	
	@Autowired
	private SeatService seatService;
	
	@Bean
	public JobDetailFactoryBean jobDetailFactoryBean() {
		JobDetailFactoryBean bean = new JobDetailFactoryBean();
		JobDataMap datamap = new JobDataMap();
		datamap.put("tableService", tableService);
		datamap.put("seatService", seatService);
		bean.setJobDataMap(datamap);
		bean.setJobClass(Clean_LockTableSeat_ToLocked.class);
		return bean;
		
	}
	
	//配置CronTrrigger
	@Bean
	public CronTriggerFactoryBean cronTriggerFactoryBean() {
		CronTriggerFactoryBean trigger = new CronTriggerFactoryBean();
		trigger.setJobDetail(jobDetailFactoryBean().getObject());
		trigger.setCronExpression("6 * * * * ?");
		return trigger;
	}
	
	
	
	@Bean
	public SchedulerFactoryBean schedulerFactoryBean() {
		SchedulerFactoryBean bean = new SchedulerFactoryBean();
		bean.setTriggers(cronTriggerFactoryBean().getObject());
		return bean;
	}
}
